<template>
	<view class="container">
		<!-- 状态栏占位 -->
		<view class="status-bar"></view>

		<!-- 页面头部 -->
		<view class="header">
			<view class="back-btn">
				<u-icon name="arrow-left" bold color="#000" size="30rpx" @click="onBack()"></u-icon>
			</view>
			<view class="title">售后详情</view>
			<view class="header-right">

			</view>
		</view>

		<scroll-view class="scroll-content" scroll-y="true">
			
		</scroll-view>

		<!-- 底部操作区 -->
		<view class="footer">
			<view class="contact-service">
				<image src="/static/serve.png" class="icon" />
				<view class="text">联系客服</view>
			</view>
			<view class="footer-btn">
				<button class="online-btn-gray" v-if="pageData.orderStatus <= 2"
					@click="showCancelPopup = true">取消订单</button>
				<button class="online-btn" v-if="pageData.orderStatus == 1">立即付款</button>
				<button class="online-btn" v-if="pageData.orderStatus == 3" @click="handleToServer">申请售后</button>
			</view>
		</view>

	</view>
</template>

<script>
	import {
		getOrderDetail,
	} from '@/request/api.js';
	import ImageUpload from '@/components/ImageUpload/ImageUpload.vue';

	export default {
		components: {
			ImageUpload,
		},
		data() {
			return {
				pageData: {},
				// 图片上传相关
				uploadedImages: [], // 已上传的图片列表

				// 提交按钮控制
				isSubmitting: false, // 防止重复提交标志
				submitTimeout: null, // 防抖定时器
			}
		},

		onLoad(option) {
			if (option.id) {

			}
		},
		methods: {

			handleEvaluate(start, mark, imgList) {
				// 防抖处理：如果正在提交中，直接返回
				if (this.isSubmitting) {
					return;
				}

				// 节流处理：清除之前的定时器
				if (this.submitTimeout) {
					clearTimeout(this.submitTimeout);
				}

				// 设置防抖延迟（300毫秒）
				this.submitTimeout = setTimeout(() => {
					this.submitEvaluate(start, mark, imgList);
				}, 300);
			},

			goBack() {
				uni.navigateBack();
			},
			copyOrderNo(order) {
				uni.setClipboardData({
					data: order,
					success: () => {
						uni.showToast({
							title: '复制成功'
						});
					}
				});
			},

			// 处理弹框关闭
			handlePopupClose() {
				this.showCancelPopup = false;
			},
			// 处理弹框关闭
			handleRefundAndChangePolicyClose() {
				this.showRefundAndChangePolicyPopup = false;
			},

			// ==================== 图片上传相关方法 ====================
			// 图片上传成功回调
			onImageUploadSuccess(file) {
				console.log('图片上传成功:', file);
				// 更新已上传图片列表
				this.uploadedImages = this.$refs.imageUploadRef.getSuccessFiles().files;
				this.$emit('image-upload-success', file);
			},

			// 图片上传失败回调
			onImageUploadError(error) {
				console.error('图片上传失败:', error);
				uni.showToast({
					title: '图片上传失败',
					icon: 'none'
				});
				this.$emit('image-upload-error', error);
			},

			// 图片删除回调
			onImageDeleted(file) {
				console.log('图片已删除:', file);
				// 更新已上传图片列表
				this.uploadedImages = this.$refs.imageUploadRef.getSuccessFiles().files;
				this.$emit('image-deleted', file);
			},


		}
	}
</script>

<style lang="scss" scoped>
	page {
		background: linear-gradient(to bottom, #FFF1D0, #F8F8F8);
		height: 100vh;
		overflow: hidden;
	}

	.container {
		height: 100vh;
		display: flex;
		flex-direction: column;

		.status-bar {
			height: var(--status-bar-height);
			width: 100%;
			flex-shrink: 0;
		}

		.header {
			display: flex;
			align-items: center;
			justify-content: space-between;
			/* 左右分布 */
			height: 80rpx;
			font-size: 36rpx;
			font-weight: bold;
			color: #333;
			position: relative;
			z-index: 10;
			padding: 0 30rpx;
			box-sizing: border-box;
			margin-top: var(--status-bar-height);

			.back-btn {
				/* 移除绝对定位，使用 flex 布局 */
				display: flex;
				align-items: center;
				justify-content: flex-start;
				width: 80rpx;
				/* 固定宽度保持平衡 */
			}

			.title {
				position: absolute;
				left: 50%;
				transform: translateX(-50%);
				text-align: center;
			}

			.header-right {
				display: flex;
				align-items: center;
				justify-content: flex-end;
				width: 120rpx;
				/* 与左边保持相同宽度 */
				color: #000000;
				/* 可选：给退改规则添加主题色 */
				font-size: 26rpx;
			}
		}

		.scroll-content {
			position: absolute;
			top: calc(80rpx + var(--status-bar-height));
			left: 0;
			right: 0;
			bottom: 160rpx;
			overflow-y: auto;
			box-sizing: border-box;
			background: linear-gradient(to bottom, #FFF1D0, #F8F8F8);
		}

		.footer {
			position: fixed;
			bottom: 0;
			left: 0;
			right: 0;
			background-color: #fff;
			padding: 30rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
			z-index: 10;

			.contact-service {
				text-align: center;
				color: #666;
				font-size: 28rpx;

				.icon {
					width: 40rpx;
					height: 40rpx;
					margin-right: 10rpx;
				}
			}

			.footer-btn {
				display: flex;

				.online-btn {
					width: 200rpx;
					height: 60rpx;
					background-color: #ff7a00;
					color: white;
					font-size: 28rpx;
					border-radius: 30rpx;
					line-height: 60rpx;
					text-align: center;
				}

				.online-btn-gray {
					width: 200rpx;
					height: 60rpx;
					background-color: #F0EFEF;
					font-size: 28rpx;
					border-radius: 30rpx;
					line-height: 60rpx;
					text-align: center;
				}

				button {
					margin-left: 10rpx;
				}
			}
		}
	}
</style>